<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>重庆大学硕士研究生服务系统</title>
<?php $this->load->view('includes/ga_head'); ?>  
</head>
<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> 
<body class=""> 
<!--<![endif]-->
<?php $this->load->view('includes/ga_navbar'); ?>  
<?php $this->load->view('includes/ga_sidebar'); ?>  
<div class="content">
    <div class="header">
        <h1 class="page-title">站内信</h1>
    </div>
    <ul class="breadcrumb">
            <li><a href="<?php echo $base_url;?>gass_news/all_public_news">Home</a> <span class="divider">/</span></li>
            <li class="active">权限信息</li>
    </ul>
    <div class="container-fluid">
        <div class="row-fluid">
<?php $this->load->view('includes/ga_message'); ?>  
<?php echo form_open(current_url());	?>
<div class="input-append">
<input type="text" placeholder="对接收人姓、名或者对话内容" class="span4 search-query" id = "sendSearchText" name="search_text" value="<?php echo $search_text; ?>">
<input type="submit" id = "submit_button" class="btn" value="搜索" />
<a class="btn" href="<?php echo $base_url; ?>gass_message/message_list/<?php echo $uId;?>">重设</a>
</div>
<?php echo form_close();?>
<?php 
  $sessionArray =array();
  $i=0;
  foreach ($messageList as $ml) 
  { 
    //判断这次会话是否出现过
    if(!in_array(array($ml['rec_id'],$ml['send_id']),$sessionArray))
    {
      //首先打印通信对象的名字，判断自己是发送者还是接收者
      $userId;
      if( $ml['send_id']==$this->flexi_auth->get_user_id())
      	$userId = $ml['rec_id'];
      else
      	$userId = $ml['send_id'];
      //获取信息
      $userInfo = $this->flexi_auth->get_user_by_id($userId)->row_array();
      //获取最后一次互相通信的时间和内容
      $sessionInfo = $this->gass_global_model->get_last_message_info($ml['send_id'],$ml['rec_id']);
      //打印信息
      //echo '<ul><li><span>'.$userInfo['upro_first_name'].' '.$userInfo['upro_last_name'].'</span>'; 
      echo '<p class="pull-right text-info message-list">'.$sessionInfo['creat_time'].'</p>';
      echo '<p class="lead message-list">'.$userInfo['upro_first_name'].' '.$userInfo['upro_last_name'].'</p>'; 
      //打印信息
      //echo "<span class='span_time'>".$sessionInfo['creat_time'].'</span></li>';
      echo "<p class='pull-right message-list'><a href='".$base_url."gass_message/message_session/".$ml['send_id']."/".$ml['rec_id']."'><i class='icon-list'></i></a>&nbsp&nbsp&nbsp&nbsp<a href='".$base_url."gass_message/session_del/".$ml['send_id']."/".$ml['rec_id']."'><i class='icon-remove'></i></a></p>";
      echo '<p class="muted message-list">'.$sessionInfo['mess_content'].'</p><hr>';
      //echo "<li><span class='span_content'>".$sessionInfo['mess_content']."</span><span class='span_details'><a href='".$base_url."gass_message/message_session/".$ml['send_id']."/".$ml['rec_id']."'>查看详细</a><a style='color:#FFD89E' href='".$base_url."gass_message/session_del/".$ml['send_id']."/".$ml['rec_id']."'>删除</a></span></li><li><span class = 'span_blank'></span></li></ul><hr>";
      $sessionArray[$i] = array($ml['send_id'],$ml['rec_id']);
      $i++;
    }
  } 
?>
<?php $attributes = array('id' => 'user_list_form');echo form_open(current_url(), $attributes);?>  	
<div class="control-group">
    <label class="control-label" >请选择发送对象</label>
    <div class="controls">
		<select class="span4 search-query" id="rec_object" name="select_rec_object" >
			<option value ="unselected" >请选择</option>
			<?php foreach ( $college_teacher_array as $cta ){ ?>
			<option value = <?php echo $cta['upro_id'] ?> ><?php echo $cta['college_name'] ?></option>
			<?php } ?>
        </select>
    </div>
</div>
<div class="control-group">
    <label class="control-label" >内容</label>
    <div class="controls">
<textarea id = "sendMessageText" class="span4" rows="3"></textarea>
    </div>
</div>
<div class="control-group">
    <label class="control-label" ></label>
    <div class="controls">
   <input type="button" id = "send_button" value="发 送" disabled class="btn" />
    </div>
</div>

<?php echo form_close();?>
<?php $this->load->view('includes/ga_footer'); ?>  
        </div>
    </div>
</div>
<?php $this->load->view('includes/ga_scripts'); ?>
<script>
$(function() {
  //为发送按钮绑定事件，并默认为jquery ui的button样式。
  $( "input[type=button]" ).click(function( event ) {
      var sendMessageText = $("#sendMessageText").val();
      var recObjectId = $("#rec_object").val();
			if (recObjectId=='unselected'){
				alert('请选择接收对象！');
				return false;
			}
			if (sendMessageText.length==0||sendMessageText.length>140){
				alert('信息长度有误，请控制在75个字以内！');
				return false;
			}      
      $.ajax({
         type:"post",
         data: "recId=" + recObjectId + "&text=" + sendMessageText,
         url: "<?php echo base_url();?>gass_message/send_message",
         success: function(result){
             //$("#photoboard").fadeTo("slow", 0.85).fadeIn("normal").html(result);
             //alert("发送成功");
             //$( "#dialog-form" ).dialog( "close" );
             location.reload();
         },
         error: function(){
             //$("#loading_message").hide();
             alert("ajax error");
         }
      });      
    });
    //对输入框的文字进行动态判断  
    //IE
    if(window.attachEvent){
      $("#sendMessageText").get(0).attachEvent("onpropertychange",function (o){
         //if(o.srcElement.value) $( "#send_button" ).button( "option", "disabled", false );
         if(o.srcElement.value) $( "#send_button" )[0].disabled=false;
         else $( "#send_button" )[0].disabled=true;
      });
      $("#sendSearchText").get(0).attachEvent("onpropertychange",function (o){
         if(o.srcElement.value) $( "#submit_button" )[0].disabled=false;
         else $( "#submit_button" )[0].disabled=true;
      });
      //非IE
    }else{
      $("#sendMessageText").get(0).addEventListener("input",function(o){
        if(o.srcElement.value) $( "#send_button" )[0].disabled=false;
        else $( "#send_button" )[0].disabled=true;
      },false);
      $("#sendSearchText").get(0).addEventListener("input",function(o){
        if(o.srcElement.value) $( "#submit_button" )[0].disabled=false;
        else $( "#submit_button" )[0].disabled=true;
      },false);
    }
});
</script>
</body>
</html>
